package com.damieoa.damieoa.service;

import com.damieoa.damieoa.dao.StaffStatusMapper;
import com.damieoa.damieoa.pojo.Staff;
import com.damieoa.damieoa.pojo.StaffStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StaffStatusServiceImpl implements StaffStatusService {

    @Autowired
    private StaffStatusMapper staffStatusMapper;

    //根据员工id获取员工姓名和调转前部门
    @Override
    public Staff queryStaffById(Staff staff) {
        return staffStatusMapper.queryStaffById(staff);
    }

    //员工部门调动
    @Override
    public void StaffDepartment(StaffStatus staffStatus) {
        //获取员工调转前的部门
        Staff staff = staffStatusMapper.getStaffAfterDeptSta(staffStatus);
        //更新员工部门
        staffStatusMapper.updateStaffDepartment(staffStatus);
        //设置员工调转前的部门
        staffStatus.setAfter_dept(staff.getDepartment());
        //更新员工部门状态
        staffStatusMapper.StaffDepartment(staffStatus);
    }

    //员工岗位调动
    @Override
    public void StaffStation(StaffStatus staffStatus) {
        //获取员工调转前的岗位
        Staff staff = staffStatusMapper.getStaffAfterDeptSta(staffStatus);
        //更新员工岗位
        staffStatusMapper.updateStaffStation(staffStatus);
        //设置员工调转前的岗位
        staffStatus.setAfter_sta(staff.getStation());
        //更新员工岗位状态
        staffStatusMapper.StaffStation(staffStatus);
    }

    //员工离职
    @Override
    public void StaffDimission(StaffStatus staffStatus) {
        staffStatusMapper.updateById(staffStatus);
    }

}
